﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;


namespace BLL
{
    public class PhotoBLL:IPhotoBLL
    {
        public bool uploadPhoto(Model.Photo photo)
        {
            bool validator = false;
            DAL.PhotoDAL photoDal = (DAL.PhotoDAL)DALFAC.DataAccess.CreatePhoto();
            if (null != photoDal)
            {
                validator = photoDal.Add(photo);
            }
            return validator;
        }

        public bool deletePhoto(int photoId)
        {
            bool validator = false;
            DAL.PhotoDAL photoDal = (DAL.PhotoDAL)DALFAC.DataAccess.CreatePhoto();
            DAL.CommentDAL commentDAL = (DAL.CommentDAL)DALFAC.DataAccess.CreateComment();
            DAL.ShareDAL shareDAL = (DAL.ShareDAL)DALFAC.DataAccess.CreateShare();

            if (null != photoDal && null != commentDAL &&null != shareDAL)
            {
                if (commentDAL.deleteAllByPhotoId(photoId))
                {
                    if (shareDAL.deleteShareByPhotoId(photoId))
                    {
                        validator = photoDal.photoDeleteById(photoId);
                    }
                }
            }
            return validator;
        }

        public bool modifyPhoto(Model.Photo photo)
        {
            bool validator = false;
            DAL.PhotoDAL photoDal = (DAL.PhotoDAL)DALFAC.DataAccess.CreatePhoto();
            if (null != photoDal)
            {
                validator = photoDal.Update(photo);
            }
            return validator;
        }

        public Model.Photo psPhoto(Model.Photo photo)
        {
            throw new NotImplementedException();
        }
    }
}
